<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */

namespace App\Controller;
use App\Model\Menu;

class MenuController extends AbstractController
{
    public function getList()
    {
        $query = Menu::with('children');

        $list = $query->where('parent_id', 0)->get();

        foreach ($list as &$item) {
            if (!$item->is_button) {
                $item->type_desc = match ($item->type) {
                    'PAGE' => '页面',
                    'CATALOG' => '目录',
                    'IFRAME' => '内嵌Iframe',
                    'REDIRECT' => '外链跳转',
                    'ACTION' => '操作',
                    default => '未知',
                };
            } else {
                $item->type = 0;
                $item->type_desc = '';
            }
        }

        return $this->success($list);
    }
}
